package weibo4j;

import java.util.HashMap;
import java.util.Map;

import weibo4j.http.HttpClient;

/**
 * @author sinaWeibo
 *
 */

public class Weibo implements java.io.Serializable {

	private static final long serialVersionUID = 4282616848978535016L;

	/*public static HttpClient client = getHttpClient();*/
	public static final String DEFAULT_TOKEN = "default_token";

	/**
	 * 保存用户的HttpClient
	 * 		key为用户的token
	 * 		value为用户对应的HttpClient
	 */
	public static Map<String, HttpClient> httpClientMap = new HashMap<String, HttpClient>();

	/**
	 * Sets token information
	 *
	 * @param token
	 * @return
	 */
	public static HttpClient setToken(String token) {
		HttpClient httpClient = new HttpClient();
		httpClient.setToken(token);
		httpClientMap.put(token, httpClient);
		return httpClient;
	}

	/**
	 * 获取对应的HttpClient
	 * @param token
	 * @return
	 */
	public static HttpClient getHttpClient(String token) {
		HttpClient httpClient = httpClientMap.get(token);
		if(httpClient == null) {
			httpClient = setToken(token);
		}
		return httpClient;
	}

}